/**
 * Created by Chris on 14-9-5.
 */

define(['jquery'], function($) {


    //冒泡提示信息: msg:提示内容, targetEl 目标DIV， duration:停留时间
    var Toast = function(msg, targetEl, duration) {
        duration = isNaN(duration) ? 2000 : duration;
        var m = document.createElement('div');
        m.innerHTML = msg;
        m.id="toastDiv";
        m.style.cssText = "width:60%; min-width:150px; background:#000; opacity:0.5; min-height:40px; color:#fff; line-height:20px; text-align:center; border-radius:5px; position:fixed; top:40%; left:20%; z-index:999999; font-weight:bold;padding:5px;"+
            "display: -webkit-box;"+
            "-webkit-box-orient: horizontal;"+
            "-webkit-box-pack: center;"+
            "-webkit-box-align: center;"+
            "display: -moz-box;"+
            "-moz-box-orient: horizontal;"+
            "-moz-box-pack: center;"+
            "-moz-box-align: center;"+
            "display: -o-box;"+
            "-o-box-orient: horizontal;"+
            "-o-box-pack: center;"+
            "-o-box-align: center;"+
            "display: -ms-box;"+
            "-ms-box-orient: horizontal;"+
            "-ms-box-pack: center;"+
            "-ms-box-align: center;"+
            "display: box;"+
            "box-orient: horizontal;"+
            "box-pack: center;"+
            "box-align: center;";


//        document.body.appendChild(m);
        targetEl.appendChild(m);
        setTimeout(function() {
            var d = 2;
            m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
            m.style.opacity = '0';
            setTimeout(function() {
                if (m) {
//                    document.body.removeChild(m);
                    targetEl.removeChild(m);
                }
            }, d * 1000);
        }, duration);
    };


    return Toast;
});